package com.itheima.health.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.TPhysicalexamrecordMapper;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.pojo.Member;
import com.itheima.health.pojo.Order;
import com.itheima.health.pojo.TPhysicalexamrecord;
import com.itheima.health.service.TPhysicalexamrecordService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * (TPhysicalexamrecord)表服务实现类
 *
 * @author makejava
 * @since 2021-05-10 15:35:11
 */
@DubboService
public class TPhysicalexamrecordServiceImpl implements TPhysicalexamrecordService {
    @Autowired
    private TPhysicalexamrecordMapper tPhysicalexamrecordDao;

    @Override
    public TPhysicalexamrecord findById(Integer id) {
        return  tPhysicalexamrecordDao.selectByPrimaryKey(id);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        //获取查询条件
        String queryString = queryPageBean.getQueryString();
        //分页查询起始
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        //获取example对象
        Example example = new Example(TPhysicalexamrecord.class);
        Example.Criteria criteria = example.createCriteria();
        String orderStatus = queryPageBean.getOrderStatus();

        //判断查询条件是否为空,模糊查询
        if (!StringUtils.isEmpty(queryString)) {
            criteria.orLike("filenumber", "%" + queryString + "%");
            criteria.orLike("name", "%" + queryString + "%");
            criteria.orLike("phonenumber", "%" + queryString + "%");
        }

        if (!StringUtils.isEmpty(orderStatus)){
            criteria.andLike("orderStatus", "%" + orderStatus + "%");
        }

        Page<TPhysicalexamrecord> page = (Page<TPhysicalexamrecord>) tPhysicalexamrecordDao.selectByExample(example);
        List<TPhysicalexamrecord> tPhysicalexamrecords = page.getResult();
        long total = page.getTotal();
        return new PageResult(total, tPhysicalexamrecords);
    }

    @Override
    public TPhysicalexamrecord add(TPhysicalexamrecord tPhysicalexamrecord,String status) {
        tPhysicalexamrecord.setOrderStatus(status);
        tPhysicalexamrecordDao.insertSelective(tPhysicalexamrecord);
        return tPhysicalexamrecord;
    }

    @Override
    public boolean deleteById(Integer id) {
        int i = tPhysicalexamrecordDao.deleteByPrimaryKey(id);
        return i != 0;
    }

    @Override
    public void edit(TPhysicalexamrecord tPhysicalexamrecord) {
         tPhysicalexamrecordDao.updateByPrimaryKeySelective(tPhysicalexamrecord);
    }

    @Override
    public  List<TPhysicalexamrecord>  findAll() {
        return tPhysicalexamrecordDao.selectAll();
    }

    @Override
    public List<TPhysicalexamrecord> findAll(String status) {
        Example example = new Example(TPhysicalexamrecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("orderStatus", Order.ORDERREPORT_YES);
        List<TPhysicalexamrecord> tPhysicalexamrecords = tPhysicalexamrecordDao.selectByExample(example);
        return tPhysicalexamrecords;
    }

    @Override
    public List<TPhysicalexamrecord> findByMemberId(Integer memberId) {
        Example example = new Example(TPhysicalexamrecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("memberId",memberId.toString());
        List<TPhysicalexamrecord> tPhysicalexamrecord = tPhysicalexamrecordDao.selectByExample(example);
        return tPhysicalexamrecord;
    }
}
